<%@ page contentType="text/html; charset=utf-8" language="java"  errorPage="" %>
<%@page import="com.netscenery.yang.model.YangString"%>
<%@page import="operate.OperateType"%>
<%@page import="com.netscenery.yang.model.RangeEx"%>
<%@page import="com.netscenery.yang.model.Pattern"%>
<%@page import="offer.SessionObj"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
YangString yangString = new YangString();
//获取结点对象
Object itemNode = request.getAttribute("itemNode");
Object opType   = request.getAttribute("opType"); //获取操作对象
if( null != itemNode){
	yangString = (YangString)itemNode;
}
//Session ModuleStatus control
SessionObj sessionObj = (SessionObj)request.getSession().getAttribute("sessionObj");
String control_disabled = "";
if(!sessionObj.getModuleStatus().toString().equalsIgnoreCase("EDITING")){
 	control_disabled ="disabled='disabled'";
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>YangString</title>
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/items.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/subItems.css" />
    <script type="text/javascript"  src="<%=basePath%>jstree-v.pre1.0/_lib/jquery.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/index.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/StrInteSupport.js"></script>
</head>

<body class="body">
<script type="text/javascript">
 function bodyLoad(){
   <% if( (null != itemNode) 
        &&  (!opType.toString().equalsIgnoreCase(OperateType.LOAD))){ %>
   <%   	 if(opType.toString().equalsIgnoreCase(OperateType.ADD)){ %>
   <%   	 } %>
			 $("#opNoticeSpan").html("操作成功！");
   		 	 setTimeout(function(){$("#opNoticeSpan").html("")},3000);
   <% }%>
 }
</script>
 <form id="yangStringForm" method="post" action="<%=basePath %>YangStringOpreateServlet" class="IndexFormStyle" >
   <input type="hidden"  id="nodeId" name="nodeId" value="<%=request.getAttribute("nodeId") %>"  />
   <div id="TableContent" class="typeSubContent" >
      <div class="itemTitle">
          The Type [<%=yangString.getClass().getSimpleName() %>] information 
      </div>
      &nbsp;Type name:&nbsp;<input class="inputText" id="_name" name="_name" value="<%=yangString.getName() %>" readonly="readonly" /><br/><br/>
      <input type="hidden" id="range_para" name="range_para" value="" />
      <!-- <input type="button" value="getStr" onclick="getStr()" /> -->
      <!-- ************Range Length Begin******************************************************************************** -->
      <div class="inContent" >
        &nbsp;Length:<input type="button" id="B_rangeAdd" name="B_rangeAdd" value="add" /><br/>
        <div id="rangeContent" class="itemContent">
        <div id="rangeItemContent">
	   <% RangeEx rangeEx = null;
	      if(null != yangString.getLength() && 0 != yangString.getLength().getRangesSize()){
	      	for(int i = 0 ; i < yangString.getLength().getRangesSize() ; i++ ){
	      		rangeEx = yangString.getLength().getRange(i);
	   %>
	   		<div class="rangeItem">
		     	From <input type='text' name='ranges_min' class='integerText' value=<%=rangeEx.getMin() %> /> 
		     	To <input  type='text' name='ranges_max' class='integerText' value=<%=rangeEx.getMax() %> />
		     	<a href='#' class='rangeRemove' onclick='rangeDelete(this)' ><img class='buttonBcImg' width='25' src='<%=basePath%>/images/delete.png' /></a>
		     	<a href='#' class='rangeAdd' onclick='rangeAdd()' ><img class='buttonBcImg' width='25' src='<%=basePath%>/images/add.png' /></a>
	     	</div>
	   <%
	      	}
	      }
	   %>
        </div><!--rangeItemContent div end  -->
        <div id = "rangeDesContent">
         <%  if(null != yangString.getLength() && yangString.getLength().getRangesSize() > 0){ %>
	     	Description:<br/>
            <textarea class="intextArea"  id="range_description" name="range_description"><%=yangString.getLength().getDescription()==null?"":yangString.getLength().getDescription() %></textarea>
            Reference:<br/>
            <textarea class="intextArea"  id="range_reference"   name="range_reference"><%=yangString.getLength().getReference()==null?"":yangString.getLength().getReference() %></textarea>    
        <% } %>
        </div>
        </div><!-- id="rangeContent" class="itemContent" end  -->
      </div><!-- inContent end  -->
      <!-- ************Range Length End******************************************************************************** -->
      <br/>
      <!-- ************Patterns Length Begin******************************************************************************** -->
      <div class="inContent">
        &nbsp;Patterns:<input type="button" id="B_patternAdd" name="B_patternAdd" value="add" />
         <input type="hidden" id="patterns" name="patterns" value="" />
         <!-- <input type="button" value="getStr" onclick="getPatternStr()" /> --> <br/> 
        <div id="patternItemContent" class="itemContent">
     <% Pattern pattern = null;
        if( 0 != yangString.getPatternsNumber()){
           for(int i = 0 ; i < yangString.getPatternsNumber() ; i++){
        	  pattern = yangString.getPattern(i);
     %>
     	   <div class="patternItem">
	            <div id="pattern_title">
	              <div class="patternLeft">Pattern Name:</div>
	              <div class="patternRight">
	                <a href="#" class="rangeRemove" onclick="patternDelete(this)" ><img class="buttonBcImg" width="20" src="<%=basePath%>/images/delete.png" /></a>
			     	<a href="#" class="rangeAdd" onclick="patternAdd()" ><img class="buttonBcImg" width="20" src="<%=basePath%>/images/add.png" /></a>
		     	  </div>
		     	  <div style="clear:both;"></div>
	            </div><!--  pattern_title end -->
            <textarea class="intextArea"  id="pattern_name" name="pattern_name"><%=pattern.getName().replaceAll("\\\\\\\\","\\\\") %></textarea>
            Description:<br/>
            <textarea class="intextArea"  id="pattern_description" name="pattern_description"><%=pattern.getDescription()==null?"":pattern.getDescription() %></textarea>
            Reference:<br/>
            <textarea class="intextArea"  id="pattern_reference" name="pattern_reference"><%=pattern.getReference()==null?"":pattern.getReference() %></textarea>
           </div>
     <%	
           }
        }
     %>
        </div><!--  patternItemContent end -->
      </div><!-- inContent end  -->
      <!-- ************Patterns Length Begin******************************************************************************** -->
      
   </div>
   <div id="submitContent" class="submitContent">
     <span id="opNoticeSpan" style="color:red;" ></span>
     <span class="textSpan">&nbsp;</span>
     <input type="button" onclick="fromSubmit()" value="Apply" <%=control_disabled %>  />
   </div>
   </form>
 <script type="text/javascript">
	 $(document).ready(function(){
	        if( $("div#rangeItemContent").html().trim().length != 0){$("input#B_rangeAdd").hide();}
	        if( $("div#patternItemContent").html().trim().length != 0){$("input#B_patternAdd").hide();}
	 		$("input#B_rangeAdd").click(function(){rangeAdd();});
	 		$("input#B_patternAdd").click(function(){patternAdd();});
	 		
	 		 bodyLoad();
	 	}
	 );
	 function fromSubmit(){
	    if(getRangeStr() && getPatternStr()){
	       document.getElementById("yangStringForm").submit();
	    }
	 }
 </script>
   
</body>
</html>